package com.handpay.nocardpay.baselibrary.onlinemarket.view.widget;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;

import com.handpay.nocardpay.baselibrary.logutils.HPLog;

import java.text.NumberFormat;

/**
 * Created by lyang on 2018/1/16.
 */

public class MoneyEditText extends android.support.v7.widget.AppCompatEditText implements TextWatcher {
    public MoneyEditText(Context context) {
        super(context);
    }

    public MoneyEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.addTextChangedListener(this);
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void afterTextChanged(Editable s) {
        String temp = s.toString();
        int posDot = temp.indexOf(".");
        if (posDot == -1) {
            if (temp.length() > 6) {
                s.delete(temp.length() - 1, temp.length());
            }
            return;
        }
        if (temp.length() - posDot - 1 > 2) {
            s.delete(posDot + 3, posDot + 4);
        }
    }
}
